package org.emf.plugins.tomcatlauncher.server;

/**
 * Kyah Request object.
 */
public class KyahRequest {

    /** Command part of this request. */
    private Command mCommand;

    /** Class constructor. */
    KyahRequest(Command command) {
        mCommand = command;
    }

    /**
     * Gets the request command.
     * @return the request command.
     */
    public Command getCommand() {
        return mCommand;
    }

    /**
     * Commands available.
     */
    public enum Command {
        /** Sent to stop server. */
        STOP("stop"),
        /** Sent to start server. */
        START("start");

        /** Command name. */
        private String mName;

        /** Enum constructor.*/
        Command(String name) {
            mName = name;
        }

        /**
         * Gets the most representative command for the string message informed
         * as parameter.
         * @param cmd command in a string format.
         * @return the command object.
         */
        public static Command get(String cmd) {
            for (Command command : Command.values()) {
                if (command.mName.equals(cmd)) {
                    return command;
                }
            }
            return null;
        }

        /**
         * Gets the command name.
         * @return the command name.
         */
        public String getName() {
            return mName;
        }
    }

}
